package com.dahuyou.tryy.too.simulate.interpreter.parse.clazz.classpath.entry.impl;

import com.dahuyou.tryy.too.simulate.interpreter.parse.clazz.classpath.entry.Entry;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 目录形式的entry 如 d:\test
 */
public class DirectoryEntry implements Entry {
    private Path absolutePath;

    public DirectoryEntry(String path) {
        //获取绝对路径
        this.absolutePath = Paths.get(path).toAbsolutePath();
    }

    @Override
    public byte[] readClass(String className) throws IOException {
        return Files.readAllBytes(absolutePath.resolve(className));
    }

    @Override
    public String toString() {
        return this.absolutePath.toString();
    }
}
